package com.oa.entity;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

/**
 * @author FengMengHuo
 * 这是个 用户类
 * 用户 多<-->多 岗位
 * 用户 多<-->一 部门
 */
public class User {
	
	private String unique_id ;//用户唯一ID
	private String user_loginName; // 用户登录名
	private String user_password; // 用户密码
	private String user_name; // 用户真实姓名
	private String user_gender; // 用户性别
	private String user_phoneNumber; // 用户电话号码
	private String user_email; // 用户电子邮件
	private Date user_regisTime; // 用户注册时间
	private String user_description; // 用户说明
	private Department department;//用户所属部门
	private Set<Post> postSet = new HashSet<Post>();//岗位类的集合
	private Set<Mark> markSet = new HashSet<Mark>(); //我的便签
	public User(){
		Date date=null;
		try {
			date = new SimpleDateFormat("yyyy-MM-dd").parse(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		
		this.user_regisTime = date;
	}
	/**
	 * 判断本用户是否有指定名称的权限
	 */
	public boolean hasPowerByName(String name) {
		System.out.println(name+"[name]");
		// 管理员有所有的权限
		if (isAdmin()) {
			return true;
		}

		// 普通用户要判断是否含有这个权限
		for (Post post : postSet) {
			for (Power power : post.getPowerSet()) {
				if (power.getPower_name().equals(name)) {
					return true;
				}
			}
		}
		return false;
	}

	/**
	 * 判断本用户是否是超级管理员
	 */
	public boolean isAdmin() {
		return "admin".equals(user_loginName);
	}
	
	
	
	//========================get(),set()方法========================
	public String getUnique_id() {
		return unique_id;
	}
	public void setUnique_id(String unique_id) {
		this.unique_id = unique_id;
	}
	public String getUser_loginName() {
		return user_loginName;
	}
	public void setUser_loginName(String user_loginName) {
		this.user_loginName = user_loginName;
	}
	public String getUser_password() {
		return user_password;
	}
	public void setUser_password(String user_password) {
		this.user_password = user_password;
	}
	public String getUser_name() {
		return user_name;
	}
	public void setUser_name(String user_name) {
		this.user_name = user_name;
	}
	public String getUser_gender() {
		return user_gender;
	}
	public void setUser_gender(String user_gender) {
		this.user_gender = user_gender;
	}
	public String getUser_phoneNumber() {
		return user_phoneNumber;
	}
	public void setUser_phoneNumber(String user_phoneNumber) {
		this.user_phoneNumber = user_phoneNumber;
	}
	public String getUser_email() {
		return user_email;
	}
	public void setUser_email(String user_email) {
		this.user_email = user_email;
	}
	public Date getUser_regisTime() {
		return user_regisTime;
	}
	public void setUser_regisTime(Date user_regisTime) {
		this.user_regisTime = user_regisTime;
	}
	public String getUser_description() {
		return user_description;
	}
	public void setUser_description(String user_description) {
		this.user_description = user_description;
	}
	public Department getDepartment() {
		return department;
	}
	public void setDepartment(Department department) {
		this.department = department;
	}
	public Set<Post> getPostSet() {
		return postSet;
	}
	public void setPostSet(Set<Post> postSet) {
		this.postSet = postSet;
	}
	public Set<Mark> getMarkSet() {
		return markSet;
	}
	public void setMarkSet(Set<Mark> markSet) {
		this.markSet = markSet;
	}
}
